package com.cytech.cloudclinic.moudle.login;

import com.cytech.cloudclinic.AccountInfo;
import com.cytech.cloudclinic.base.BaseBean;
import com.cytech.cloudclinic.base.BaseObserver;
import com.cytech.cloudclinic.base.BasePresenter;
import com.cytech.cloudclinic.bean.UserInfo;
import com.yechaoa.yutils.ToastUtil;

public class LoginPresenter extends BasePresenter<LoginView> {

    public LoginPresenter(LoginView baseView) {
        super(baseView);
    }

    /**
     * 登录
     */
    void login(String phone,String password) {
        UserInfo userInfo = new UserInfo(phone,password);
        addDisposable(apiServer.login(objectToRequestBody(userInfo)), new BaseObserver<BaseBean<UserInfo>>(baseView, true) {

            @Override
            public void onSuccess(BaseBean<UserInfo> o) {
                baseView.loginSuccess(o.result.token);
            }

            @Override
            public void onError(String msg) {
                ToastUtil.showToast(msg);
            }
        });
    }

    void getUserInfo(){
        addDisposable(apiServer.getUserInfo(), new BaseObserver<BaseBean<AccountInfo>>(baseView, true) {

            @Override
            public void onSuccess(BaseBean<AccountInfo> o) {
                    baseView.getUserInfoSuccess(o.result);
            }

            @Override
            public void onError(String msg) {
                ToastUtil.showToast(msg);
            }
        });
    }
}
